<%@page import="form.Valider"%>
<%@page import="bean.Patient"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<jsp:useBean id="patient" scope="request" class="bean.Patient" />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <SCRIPT language=javascript>
    function confirmAjout() {
    	alert('Patient(e) ajoute(e)');   
    }
  </SCRIPT>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ajouter un patient</title>
</head>
<body>
<%
String sessionUser = (String) session.getAttribute("username");
if (sessionUser == null){
	response.sendRedirect("../modele/modele.jsp");
	return ;
}
%>
<%@ include file="../commun_page_swmenufree/swmenufree.jsp" %>
<jsp:include page="${pageConfig.contenu}" />
<%
if (request.getParameter("submit") != null) {
	boolean res = Valider.form(request,patient);
	//patient.createDate();
	out.println(""+patient.getJour());
	out.println(""+patient.getMois());
	out.println(""+patient.getAnnee());
	out.println(""+patient.getDateNaissance());
	//out.println("validation: "+res);
	if (res){
		System.out.println(""+patient.getDateNaissance());
		Patient.enregistrerPatient(patient);
		out.println("<script type=\"text/javascript\">");
		out.println("	alert (\"Patient(e) ajoute(e)\");");
		out.println("	window.location.replace(\"../patient/listePatient.jsp\");");
		out.println("</script>");
	}
}
%>
<h3>Creation d'un nouveau patient</h3>
<form method="post">
	<table>
	<tr>
		<td>Nom : </td>
		<td><input type="text" name="nom" value="${patient.nom}" size=55 maxlength=255 /> * </td>
		<td>${patient.err.nom}</td>
	</tr>
	<tr>
		<td>Prenom : </td>
		<td><input type="text" name="prenom" value="${patient.prenom}" size=55 maxlength=255 /> *</td>
		<td>${patient.err.prenom}</td>
	</tr>
	<tr>
		<td>Date de naissance : </td>
		<td><SELECT NAME=jour>
			<option> --
				<%
				for (int i = 1; i <= 31; i++){
					out.print("<OPTION");
					if(i==patient.getJour()) {
						out.print(" SELECTED");
					}
					out.println(">"+i);
				}
				%>
			</SELECT>
			<SELECT NAME=mois>
			<option> --
				<%
				for (int i = 1; i <= 12; i++){
					out.print("<OPTION");
					if(i==patient.getMois()) {
						out.print(" SELECTED");
					}
					out.println(">"+i);
				}
				%>
			</SELECT>
			<SELECT NAME=annee>
			<option> ----
				<%
				for (int i = 1910; i <= 2011; i++){
					out.print("<OPTION");
					if(i==patient.getAnnee()) {
						out.print(" SELECTED");
					}
					out.println(">"+i);
				}
				%>
			</SELECT> *
		</td>	
		<td>${patient.err.dateNaissance}</td>
	</tr>
	<tr>
		<td>Adresse : </td>
		<td><input type="text" name="adresse" value="${patient.adresse}" size=55 maxlength=255/> *</td>
		<td>${patient.err.adresse}</td>
	</tr>
	<tr>
		<td>Code Postal : </td>
		<td><input type="text" name="codePostal" value="${patient.codePostal}" size=5 maxlength=5/> *</td>
		<td>${patient.err.codePostal}</td>
	</tr>
	<tr>
		<td>Ville : </td>
		<td><input type="text" name="ville" value="${patient.ville}" size=55 maxlength=255/> *</td>
		<td>${patient.err.ville}</td>
	</tr>
	<tr>
		<td>Telephone : </td>
		<td><input type="text" name="numTel" value="${patient.numTel}" size=10 maxlength=10/> *</td>
		<td>${patient.err.numTel}</td>
	</tr>
	<tr>
		<td>Poids : </td>
		<td><input type="text" name="poids" value="${patient.poids}" size=10 maxlength=6/> *</td>
		<td>${patient.err.poids}</td>
	</tr>
	<tr>
		<td> <h4><font color="red">*: champs obligatoires</font></h4></td>
		<td></td>
		<td></td>
	</tr>
	<tr>
		<td></td>
		<td><input type="submit" name="submit" value="Creer le patient"/></td>
		<td></td>
	</tr>
	
	</table>
</form>
</body>
</html>